<template>
  <div class="wrapper">
    <swiper :options="swiperOption" ref="mySwiper" class="swiper" v-if="swiperList.length>0">
      <!-- slides -->
      <swiper-slide v-for="item in swiperList" :key="item.id" class="swiper-item">
        <a href="#">
          <img :src="item.imgUrl" class="swiper-img" alt />
        </a>
      </swiper-slide>
      <!-- Optional controls -->
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: "HomeSwiper",
  data() {
    return {
      swiperOption: {
        loop: true,
        pagination: {
          el: ".swiper-pagination"
        },
        autoplay: {
          delay: 2000,
          disableOnInteraction: false
        }
      }
    };
  },
  props: {
    swiperList: Array
  }
  // 当图片加载时，在未加载出来之前，那么轮播图的高度为0，下面的内容就顶上来了。加载完成了，又回去了。
  // .wrapper做法防止这种抖动现象
};
</script>

<style lang="stylus" scoped>
.wrapper >>> .swiper-pagination-bullet-active
  background: #fff
.wrapper
  width: 100%
  height: 0
  padding-bottom: 2rem
  overflow: hidden
  background: #ccc
.swiper
  height: 2rem
  .swiper-item
    a
      display: block
      .swiper-img
        width: 100%
</style>
